function ax=adjust_axis(pos)
% adjust_axis: Adjust current axis to center at specified position
%
% SYNTAX:
%   ax = adjust_axis(pos)
%   Return adjusted axis ranges

%   Author: Hongbin Ma
%   Last updated: 2009-6-1 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com

ax=axis;
dx=0;dy=0;dz=0;
if pos(1)>ax(2)|pos(1)<ax(1),
    cx=(ax(1)+ax(2))/2;
    dx=pos(1)-cx;
end;
if pos(2)>ax(4)|pos(2)<ax(3),
    cy=(ax(3)+ax(4))/2;
    dy=pos(2)-cy;
end;
if length(ax)>4,
if pos(3)>ax(6)|pos(3)<ax(5),
    cz=(ax(5)+ax(6))/2;
    dx=pos(3)-cz;
end;
end;
if length(ax)==4,
    ax=[ax(1:2)+dx,ax(3:4)+dy];
else,
    ax=[ax(1:2)+dx,ax(3:4)+dy,ax(5:6)+dz];
end;
axis(ax);
